import java.util.*;


public class Tabel2 
{
	//HashMap<String,Integer> GenerareHashMap()
	//void afisareHashMap(HashMap<String,Integer> h )
	//int valoarea(HashMap<String,Integer> h,String query)
	//void afisareTimpiInterval(String q1,String q2)
 
	float calculareInterval2(int v1, int v2)
	{
		
		float consum=0;//pe 6 secunde
		float interval=6;
		float sec=3600;//3600
		
		if(v1>v2) consum= ( v1/sec*interval+((v2/sec-v1/sec)*interval)/2 );//calcularea se face pe ora dar aria pe secunde 
			else if(v1<v2) consum= ( v2/sec*interval+((v1/sec-v2/sec)*interval)/2 );
						else consum=v1/sec*interval;
		//if(v1>v2) consum=v1-v2;
		//else if(v2>v1) consum=v2-v1;
				
		return consum;
					
	}//calculareInterval2

	
	HashMap<String,Integer> GenerareHashMap()
	{
		String s;
		int interval=6;
		HashMap<String,Integer> h = new HashMap<String,Integer>();
		
		for(int i=0; i<=24; i++)
		{
			for(int j=0; j<60; j++)
			{
				for(int k=0; k<60; k=k+interval)
				{
					if(i<=9) 
						if(j<=9)
							if(k<=9)
							{
									s="0"+Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+"0"+Integer.toString(k);
									//System.out.println(s);
							}
							else
							{
								
									s="0"+Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+Integer.toString(k);
								    //System.out.println(s);
							}
							
						else 
							if(k<=9)
							{
								s="0"+Integer.toString(i)+":"+Integer.toString(j)+":"+"0"+Integer.toString(k);
								//System.out.println(s);
							}
							else  
							{
									s="0"+Integer.toString(i)+":"+Integer.toString(j)+":"+Integer.toString(k);
									//System.out.println(s);
							}
					else 
						if(j<=9)
							if(k<=9)
							{
								s=Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+"0"+Integer.toString(k);
								//System.out.println(s);
							}
							else //k>9 
							{
									s=Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+Integer.toString(k);
									//System.out.println(s);
							}
						else //j>9
							if(k<=9)
							{
									s=Integer.toString(i)+":"+Integer.toString(j)+":"+"0"+Integer.toString(k);
									//System.out.println(s);
							}
							else  
							{
								s=Integer.toString(i)+":"+Integer.toString(j)+":"+Integer.toString(k);
								//System.out.println(s);
							}
					
					Random rand=new Random();
					int valoare=rand.nextInt(100);
					h.put(s, valoare);	
					
				}//for3
							
			}//for2
						
		}//for1
	
		return h;
		
	}//GenerareHashMap
	
	void afisareHashMap(HashMap<String,Integer> h )
	{
		Iterator<String> it = h.keySet().iterator();
		
		while (it.hasNext( )) 
		{
			String key = (String)it.next();
			System.out.println("Timpul este: " + key  +" cu valoarea " + h.get(key));
		}
	}//afisareHashMap
	
	int valoarea(HashMap<String,Integer> h,String query)
	{
		//System.out.println("Ati cautat timpul: "+query);
		//System.out.println("Acesta are valoarea masurata: "+h.get(query));
		return h.get(query);
	}//valoarea
	
	void afisareTimpiInterval(String q1,String q2)
	{
		String o1,m1,s1,o2,m2,s2;
		int ora1=0,min1=0,sec1=0,ora2=0,min2=0,sec2=0;
		
		StringTokenizer st=new StringTokenizer(q1,":");
		
		o1=st.nextToken();
		try
		{
			ora1=Integer.parseInt(o1);
		}
		catch(Exception e){};
		
		m1=st.nextToken();
		try
		{
			min1=Integer.parseInt(m1);
		}
		catch(Exception e){};
		
		s1=st.nextToken();
		try
		{
			sec1=Integer.parseInt(s1);
		}
		catch(Exception e){}
		
	    st=new StringTokenizer(q2,":");
	    
		o2=st.nextToken();
		try
		{
			ora2=Integer.parseInt(o2);
		}
		catch(Exception e){}
		
		m2=st.nextToken();
		try
		{
			min2=Integer.parseInt(m2);
		}
		catch(Exception e){}
		
		s2=st.nextToken();
		try
		{
			sec2=Integer.parseInt(s2);
		}
		catch(Exception e){}
		
		if((ora1<0)||(ora1>24)||(min1<0)||(min1>59)||(sec1<0)||(sec1>59)) System.out.println("Ati gresit introducerea orei 1!");
		else if ((ora2<0)||(ora2>24)||(min2<0)||(min2>59)||(sec2<0)||(sec2>59)) System.out.println("Ati gresit introducerea orei 2!");
		
		if(ora1==ora2)
			if(min1==min2)
				for(int k=sec1;k<=sec2;k=k+6)
				{
					String s=afisareCorectaString(ora1,min1,k);
					System.out.println(s);
					
					
				}
			else //min1 != min2
			{
				//pt min1
				for(int i=min1;i!=min1+1;i++)
				{
									
					for(int j=sec1;j<=54;j=j+6)
					{
						String s=afisareCorectaString(ora1,min1,j);
						System.out.println(s);
						//terminam min1
					
					}
				}
				
				if((min2-min1)>1)
				{
					int minute=min1+1;
					for(int i=minute;minute<min2;i++)
					{
						for(int j=0;j<=54;j=j+6)
						{
							String s=afisareCorectaString(ora1,minute,j);
							System.out.println(s);
							
						
						}
					}//for
					//terminam tot pana la min2
					for(int j=0;j<=sec2;j=j+6)
					{
						String s=afisareCorectaString(ora1,min2,j);
						System.out.println(s);
						//terminam min2
						
					}
					
					
				}//if
				
				//daca min2 este imediat dupa min1
				if((min2-min1)==1)
				{
					for(int j=0;j<=sec2;j=j+6)
					{
						String s=afisareCorectaString(ora1,min2,j);
						System.out.println(s);
						//terminam min2
						
					}
				}//if
				
				
			}//else min
		else if(ora1<ora2)//else ore ore1 != ore2
		{
			//pt ora1
			//pt min1
			for(int i=min1;i!=min1+1;i++)
			{
								
				for(int j=sec1;j<=54;j=j+6)
				{
					String s=afisareCorectaString(ora1,min1,j);
					System.out.println(s);
					//terminam min1
				
				}
			}//for min1
			for(int i=min1+1;i<60;i++)
			{
				for(int j=0;j<60;j=j+6)
				{
					String s=afisareCorectaString(ora1,i,j);
					System.out.println(s);
					
				}
				
			}//for pt restul minutelor pt ora1
			
			if((ora2-ora1)>1)
			{
				int orele=ora1+1;
				for(int i=orele;orele<ora2;i++)
					for(int j=0;j<60;j++)
						for(int k=0;k<60;k=k+6)
						{
							String s=afisareCorectaString(orele,j,k);
							System.out.println(s);
						}
				
				for(int i=0;i<min2;i++)	
				{
					for(int j=9;j<60;j++)
						{
						String s=afisareCorectaString(ora2,i,j);
						System.out.println(s);
						}
				}
				for(int i=0;i<=sec2;i=i+6)
				{
					String s=afisareCorectaString(ora2,min2,i);
					System.out.println(s);
				}
				
				
			}//if daca exista multe ore intre ore1 si ore2
			
			if((ora2-ora1)==1)
			{
				//ultima ora
				for(int i=0;i<min2;i++)	
				{
					for(int j=9;j<60;j++)
						{
						String s=afisareCorectaString(ora2,i,j);
						System.out.println(s);
						}
				}
				for(int i=0;i<=sec2;i=i+6)
				{
					String s=afisareCorectaString(ora2,min2,i);
					System.out.println(s);
				}
			}
			
		}//else ora1 != ora2		
	}
	
	static String afisareCorectaString(int i,int j, int k)
	{
		String s;
		if(i<=9) 
			if(j<=9)
				if(k<=9)
					{
						s="0"+Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+"0"+Integer.toString(k);
						//System.out.println(s);
					}
				else
					{
					
						s="0"+Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+Integer.toString(k);
					    //System.out.println(s);
					}
				
			else 
				if(k<=9)
				{
					s="0"+Integer.toString(i)+":"+Integer.toString(j)+":"+"0"+Integer.toString(k);
					//System.out.println(s);
				}
				else  
					{
						s="0"+Integer.toString(i)+":"+Integer.toString(j)+":"+Integer.toString(k);
						//System.out.println(s);
					}
		else 
			if(j<=9)
				if(k<=9)
				{
					s=Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+"0"+Integer.toString(k);
					//System.out.println(s);
				}
				else  
					{
						s=Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+Integer.toString(k);
						//System.out.println(s);
					}
			else 
				if(k<=9)
					{
						s=Integer.toString(i)+":"+Integer.toString(j)+":"+"0"+Integer.toString(k);
						//System.out.println(s);
					}
				else  
				{
					s=Integer.toString(i)+":"+Integer.toString(j)+":"+Integer.toString(k);
					//System.out.println(s);
				}
		return s;
		
	}
	
	void afisareTimpiCuValoriInterval(HashMap<String,Integer>t,String q1,String q2)
	{
		String o1,m1,s1,o2,m2,s2;
		int ora1=0,min1=0,sec1=0,ora2=0,min2=0,sec2=0;
		
		StringTokenizer st=new StringTokenizer(q1,":");
		
		o1=st.nextToken();
		try
		{
			ora1=Integer.parseInt(o1);
		}
		catch(Exception e){};
		
		m1=st.nextToken();
		try
		{
			min1=Integer.parseInt(m1);
		}
		catch(Exception e){};
		
		s1=st.nextToken();
		try
		{
			sec1=Integer.parseInt(s1);
		}
		catch(Exception e){}
		
	    st=new StringTokenizer(q2,":");
	    
		o2=st.nextToken();
		try
		{
			ora2=Integer.parseInt(o2);
		}
		catch(Exception e){}
		
		m2=st.nextToken();
		try
		{
			min2=Integer.parseInt(m2);
		}
		catch(Exception e){}
		
		s2=st.nextToken();
		try
		{
			sec2=Integer.parseInt(s2);
		}
		catch(Exception e){}
		
		if((ora1<0)||(ora1>24)||(min1<0)||(min1>59)||(sec1<0)||(sec1>59)) System.out.println("Ati gresit introducerea orei 1!");
		else if ((ora2<0)||(ora2>24)||(min2<0)||(min2>59)||(sec2<0)||(sec2>59)) System.out.println("Ati gresit introducerea orei 2!");
		
		if(ora1==ora2)
			if(min1==min2)
				for(int k=sec1;k<=sec2;k=k+6)
				{
					String s=afisareCorectaString(ora1,min1,k);
					System.out.print(s+" are valoarea: ");
					int v=valoarea(t,s);
					System.out.println(v);
					
					
				}
			else //min1 != min2
			{
				//pt min1
				for(int i=min1;i!=min1+1;i++)
				{
									
					for(int j=sec1;j<=54;j=j+6)
					{
						String s=afisareCorectaString(ora1,min1,j);
						System.out.print(s+" are valoarea: ");
						int v=valoarea(t,s);
						System.out.println(v);
						//terminam min1
					
					}
				}
				
				if((min2-min1)>1)
				{
					int minute=min1+1;
					for(int i=minute;minute<min2;i++)
					{
						for(int j=0;j<=54;j=j+6)
						{
							String s=afisareCorectaString(ora1,minute,j);
							System.out.print(s+" are valoarea: ");
							int v=valoarea(t,s);
							System.out.println(v);
							
						
						}
					}//for
					//terminam tot pana la min2
					for(int j=0;j<=sec2;j=j+6)
					{
						String s=afisareCorectaString(ora1,min2,j);
						System.out.print(s+" are valoarea: ");
						int v=valoarea(t,s);
						System.out.println(v);
						//terminam min2
						
					}
					
					
				}//if
				
				//daca min2 este imediat dupa min1
				if((min2-min1)==1)
				{
					for(int j=0;j<=sec2;j=j+6)
					{
						String s=afisareCorectaString(ora1,min2,j);
						System.out.print(s+" are valoarea: ");
						int v=valoarea(t,s);
						System.out.println(v);
						//terminam min2
						
					}
				}//if
				
				
			}//else min
		else if(ora1<ora2)//else ore ore1 != ore2
		{
			//pt ora1
			//pt min1
			for(int i=min1;i!=min1+1;i++)
			{
								
				for(int j=sec1;j<=54;j=j+6)
				{
					String s=afisareCorectaString(ora1,min1,j);
					System.out.print(s+" are valoarea: ");
					int v=valoarea(t,s);
					System.out.println(v);
					//terminam min1
				
				}
			}//for min1
			for(int i=min1+1;i<60;i++)
			{
				for(int j=0;j<60;j=j+6)
				{
					String s=afisareCorectaString(ora1,i,j);
					System.out.print(s+" are valoarea: ");
					int v=valoarea(t,s);
					System.out.println(v);
					
				}
				
			}//for pt restul minutelor pt ora1
			
			if((ora2-ora1)>1)
			{
				int orele=ora1+1;
				for(int i=orele;orele<ora2;i++)
					for(int j=0;j<60;j++)
						for(int k=0;k<60;k=k+6)
						{
							String s=afisareCorectaString(orele,j,k);
							System.out.print(s+" are valoarea: ");
							int v=valoarea(t,s);
							System.out.println(v);
						}
				
				for(int i=0;i<min2;i++)	
				{
					for(int j=9;j<60;j++)
						{
						String s=afisareCorectaString(ora2,i,j);
						System.out.print(s+" are valoarea: ");
						int v=valoarea(t,s);
						System.out.println(v);
						}
				}
				for(int i=0;i<=sec2;i=i+6)
				{
					String s=afisareCorectaString(ora2,min2,i);
					System.out.print(s+" are valoarea: ");
					int v=valoarea(t,s);
					System.out.println(v);
				}
				
				
			}//if daca exista multe ore intre ore1 si ore2
			
			if((ora2-ora1)==1)
			{
				//ultima ora
				for(int i=0;i<min2;i++)	
				{
					for(int j=9;j<60;j++)
						{
						String s=afisareCorectaString(ora2,i,j);
						System.out.print(s+" are valoarea: ");
						int v=valoarea(t,s);
						System.out.println(v);
						}
				}
				for(int i=0;i<=sec2;i=i+6)
				{
					String s=afisareCorectaString(ora2,min2,i);
					System.out.print(s+" are valoarea: ");
					int v=valoarea(t,s);
					System.out.println(v);
				}
			}
			
		}//else ora1 != ora2		
	}
	

	
	
	//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	
	
	float calculateDay(HashMap<String,Integer> h,int afisare)
	{
		String s;
		float suma=0;
		int interval=6;
		int valStart=valoarea(h,"00:00:00");
		if (afisare==1)
		{
			System.out.print("00:00:00");
			System.out.println(" cu valoarea: "+valStart);
		}
		
						
		for(int i=0; i<=24; i++)
		{
			for(int j=0; j<60; j++)
			{		
				
				int p=0;
				if((i==0)&&(j==0)) p=6;
				else p=0;
				for(int k=p; k<60; k=k+interval)
				{					
					if(i<=9) 
						if(j<=9)
							if(k<=9)
							{
									s="0"+Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+"0"+Integer.toString(k);
									//System.out.println(s);
							}
							else
							{
								
									s="0"+Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+Integer.toString(k);
								    //System.out.println(s);
							}
							
						else 
							if(k<=9)
							{
								s="0"+Integer.toString(i)+":"+Integer.toString(j)+":"+"0"+Integer.toString(k);
								//System.out.println(s);
							}
							else  
							{
									s="0"+Integer.toString(i)+":"+Integer.toString(j)+":"+Integer.toString(k);
									//System.out.println(s);
							}
					else 
						if(j<=9)
							if(k<=9)
							{
								s=Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+"0"+Integer.toString(k);
								//System.out.println(s);
							}
							else //k>9 
							{
									s=Integer.toString(i)+":"+"0"+Integer.toString(j)+":"+Integer.toString(k);
									//System.out.println(s);
							}
						else //j>9
							if(k<=9)
							{
									s=Integer.toString(i)+":"+Integer.toString(j)+":"+"0"+Integer.toString(k);
									//System.out.println(s);
							}
							else  
							{
								s=Integer.toString(i)+":"+Integer.toString(j)+":"+Integer.toString(k);
								//System.out.println(s);
							}
					
					
					
					int val=valoarea(h,s);
					
					float rezultat2=calculareInterval2(valStart,val);
					
					//afisarea fiecarei inregistrari cu valoarea si consumul respective
					if (afisare==1)
					{
						System.out.print(s+" cu valoarea: ");
						System.out.print(val+" avand un consum de ");	
						System.out.println(rezultat2);
					}
					
					
					valStart=val;
					suma=suma+rezultat2;
					
					
			
								
				}//for3
							
			}//for2
						
		}//for1
		//System.out.println("Consumul pe zi este de "+suma+" kW");
		return suma;
		
	}//calculateDay
}//Tabel2
